package com.ayu.commentbackend.mapper;

import com.ayu.commentbackend.pojo.dto.BlogPageQueryDTO;
import com.ayu.commentbackend.pojo.entity.Blog;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BlogMapper {
    Page<Blog> pageQuery(BlogPageQueryDTO blogPageQueryDTO);

    @Insert("INSERT INTO blog (name, province, city, work_time, work_position, work_years, " +
            "monthly_salary, commission_salary, score, good_event, bad_event, other_event, " +
            "create_time, update_time, create_user, create_username,status) " +
            "VALUES (#{name}, #{province}, #{city}, #{workTime}, #{workPosition}, #{workYears}, " +
            "#{monthlySalary}, #{commissionSalary}, #{score}, #{goodEvent}, #{badEvent}, #{otherEvent}, " +
            "#{createTime}, #{updateTime}, #{createUser},#{createUsername},#{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Blog blog);

    @Select("select * from blog where id=#{id}")
    Blog selectById(Integer id);

    @Select("select * from blog where create_user=#{id}")
    List<Blog> selectByUserId(Integer createUser);

    @Delete("delete from blog where id=#{id}")
    void delete(Integer id);

    @Update("update blog set create_username=#{username} where id=#{id}")
    void updateUsername(String username, Long id);

    void update(Blog blog);

    @Update("update blog set ai_status=#{aiStatus} where id=#{id}")
    void updateAiStatus(int aiStatus, Long id);

    @Update("update blog set other_event=#{aiResult} ,ai_status=#{aiStatus}, update_time=NOW() ,status=#{status} where id=#{id}")
    void updateOtherEventWithAiStatus(String aiResult, int aiStatus,int status, Long id);
}
